package ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fy.fyzf.R;
import com.fy.fyzf.bean.DemandListBean;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

public class MydemandAdapter extends BaseQuickAdapter<DemandListBean.ListBean, BaseViewHolder> {

    public MydemandAdapter() {
        super(R.layout.item_my_demand);
    }

    public void removeItem(int i){
        getData().remove(i);
        notifyItemRemoved(i);
    }
    @Override
    protected void convert(BaseViewHolder helper, DemandListBean.ListBean item) {
        TagFlowLayout flowLayout = helper.getView(R.id.flowlayout);
        helper.addOnClickListener(R.id.tv_edit);
        helper.addOnClickListener(R.id.tv_delete);
        List<String> list = new ArrayList<>();
        list.add(item.getAreaName());
        list.add(item.getReleaseArea()+"m²");
        list.add(item.getReleaseBudget()+"元/天");
        switch (item.getRenovationType()) {
            case 0:
                list.add("装修不限");
                break;
            case 1:
                list.add("简装");
                break;
            case 2:
                list.add("精装");
                break;
            case 3:
                list.add("豪装");
                break;
            case 4:
                list.add("无装修");
                break;
        }
        switch (item.getReleaseType()) {
            case 1:
                helper.setText(R.id.tv_type, "写字楼");
                break;
            case 2:
                helper.setText(R.id.tv_type, "商铺");
                break;
            case 3:
                helper.setText(R.id.tv_type, "厂房");
                break;
            case 4:
                helper.setText(R.id.tv_type, "酒店");
                break;
            case 5:
                helper.setText(R.id.tv_type, "公寓");
                break;
        }

        flowLayout.setAdapter(new TagAdapter<String>(list) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout.item_peer_tab,
                        flowLayout, false);
                tv.setText(list.get(position));
                return tv;
            }
        });

        helper.setText(R.id.tv_time, item.getCreateTime());
        if (item.getCooperationProgram() != null) {
            switch (item.getCooperationProgram()) {
                case 1:
                    helper.setText(R.id.tv_peer_schme, "合作方案: 10%");
                    break;
                case 2:
                    helper.setText(R.id.tv_peer_schme, "合作方案: 20%");
                    break;
                case 3:
                    helper.setText(R.id.tv_peer_schme, "合作方案: 30%");
                    break;
                case 4:
                    helper.setText(R.id.tv_peer_schme, "合作方案: 40%");
                    break;
                case 5:
                    helper.setText(R.id.tv_peer_schme, "合作方案: 50%");
                    break;
            }
        }

        if (item.getOtherNeeds() != null) {
            helper.setText(R.id.tv_remark, item.getOtherNeeds());
        } else {
            helper.setText(R.id.tv_remark, "暂无其他要求描述，详情请去电咨询。");
        }

        helper.setText(R.id.responce_count, "已收到"+item.getResponseCount() + "条推荐");
    }
}
